package com.hand.qiandu.filter;


import com.sun.org.apache.xpath.internal.operations.Bool;
import com.sun.xml.internal.bind.v2.util.ByteArrayOutputStreamEx;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author 24748  刘瑞锋
 * @date 2019/7/17
 */
//@WebFilter(filterName = "permissionFilter",urlPatterns = "/")
//@Component
public class PermissionFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) {
        System.out.println("filter init");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//        HttpServletRequest httpServletRequest = (HttpServletRequest)servletRequest;
//        System.out.println(httpServletRequest.getRequestURI());
//        System.out.println(httpServletRequest.getLocalAddr());
//        Boolean result = validateUserPermission(httpServletRequest.getHeader("token"));
//        if(result){
//            filterChain.doFilter(servletRequest,servletResponse);
//            System.out.println("token true");
//        }else{
//            System.out.println("token flase");
//        }
       System.out.println("dofilter");

    }

    @Override
    public void destroy() {
        System.out.println("destroy");
    }

    private Boolean validateUserPermission(String token){

        return false;
    }
}
